package syan.sql.Thread;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

@Slf4j
public class ThreadPoolManager {
    private final static ThreadPoolManager instance = new ThreadPoolManager();
    //任务处理线程池
    ExecutorService fixedThreadPool ;
    public ThreadPoolManager() {
        log.info("创建线程池大小为："+10);
        this.fixedThreadPool= new ThreadPoolExecutor(10,
                10,
                3L,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<Runnable>(2048),
                new DefaultThreadFactory(),
                new ThreadPoolExecutor.CallerRunsPolicy());
    }
    public static ThreadPoolManager getInstance() {
        return instance;
    }


    public void AddMission(Runnable head) {
            fixedThreadPool.execute(head);
    }

    public ExecutorService getPool() {
            return fixedThreadPool;
    }
}


